<template>
    批量修改<el-upload
        :show-file-list="false"
        :before-upload="beforeUpload1"
        :on-success="onSuccess1"
        :on-error="onError1"
        :disabled="importDisabled1"
        style="display: inline-flex;margin-right: 10px;"
        :action="'http://localhost:8080/data/importUpdate?uid='+store.auth.idd">
    <el-button size="small" :disabled="importDisabled1" type="success">
        <el-icon class="el-icon--left"><Upload /></el-icon>{{importDataText1}}
        <div slot="tip" class="el-upload__tip">说明：只能上传xls或xlsx文件</div>
    </el-button>
</el-upload>
    <a href="http://localhost:8080/data/importUpdateM">下载模板</a>

    <div>
        <el-table :data="datas" style="width: 100%" max-height="600" border>
            <el-table-column fixed label="序号" width="150">
                <template #default="scopes">
                    {{ scopes.$index+1 }}
                </template>
            </el-table-column>
            <el-table-column fixed prop="realname" label="姓名" width="150" />
            <el-table-column fixed prop="part" label="所在部门" width="200" />
            <el-table-column prop="position" label="职务" width="150" />
            <el-table-column prop="isupload" label="是否上传述职报告" width="150" />
            <el-table-column prop="summarytime" label="上传时间" width="200" disabled/>
            <el-table-column fixed="right" label="操作" width="300">
                <template #default="scope">
                    <div>
                    <el-upload
                            :show-file-list="false"
                            :before-upload="beforeUpload"
                            :on-success="onSuccess"
                            accept=".docx"
                            :on-error="onError"
                            :disabled="importDisabled"
                            style="display: inline-flex;margin-right: 10px;"
                            :action="'http://localhost:8080/data/importS?uid='+scope.row.uid">
                        <el-button size="small" :disabled="importDisabled" type="success">
                            <el-icon class="el-icon--left"><Upload /></el-icon>{{importDataText}}
                            <div slot="tip" class="el-upload__tip">只能上传docx文件</div>
                        </el-button >
                    </el-upload>
                    <el-button size="small" type="success" :disabled="scope.row.isupload !== '已上传'" @click="look(scope.row)">预览</el-button>
                        <el-button type="success" @click="changeState(scope.row, '审核通过...师傅正在赶来的路上')" :disabled="scope.row.isupload !== '待审核'">审核通过</el-button>
                        <el-button type="danger" @click="changeState(scope.row, '审核不通过')" :disabled="scope.row.isupload !== '待审核'">审核不通过</el-button>
                        <el-button type="success" @click="updates(scope.row)">修改信息</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[5, 10, 20, 50]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>

        <el-dialog title="修改信息" v-model="dialogVisibles">
            <el-form :model="stus">
                <el-input placeholder="工号" v-model="stus.uid" type="text" disabled/>
                <el-input placeholder="姓名" v-model="stus.realname" type="text" disabled/>
                <el-input placeholder="所在部门" v-model="stus.part" type="text" />
                <el-input placeholder="职务" v-model="stus.position" type="text" />
                <el-button type="warning" @click="dialogVisibles=false">取消</el-button>
                <el-button type="primary" @click="send()">确认</el-button>
            </el-form>
        </el-dialog>
    </div>


</template>
<script setup>
import { ref,onMounted } from 'vue'
import {ElMessage} from 'element-plus'
import { get,post } from '@/utils/request.js'
import { reactive } from 'vue'
import * as echarts from 'echarts'
import {userStore} from '@/stores/counter.js'
import moment from 'moment'


const importDataText=ref('上传述职报告')
const importDisabled=ref(false)
const importDataText1=ref('上传批量修改中层干部信息表')
const importDisabled1=ref(false)
const dialogVisibles=ref(false)
const store=userStore()
const datas=ref([])
const score=ref([])
const score1=ref([])
const score2=ref([])
const classi=ref([])
 const currentPage=ref(1)
 const pageSize=ref(5)
 const total=ref(10)

const stus = reactive({
uid:'',
realname:'',
part:'',
position:'',
})

const updates=(row)=>{
console.log(row)
dialogVisibles.value=true
stus.uid=row.uid
stus.realname=row.realname
stus.part=row.part
stus.position=row.position
}

const send=()=>{
post('/user/update',{
uid:stus.uid,
part:stus.part,
position:stus.position
},(message)=>{
dialogVisibles.value=false
ElMessage.success(message)
findAll()
},(message)=>{
dialogVisibles.value=false
ElMessage.warning(message)
})
}

onMounted(()=>{
currentPage.value=1
findAll()
})

const findAll=()=>{
post('/user/getPage',{
currentPage:currentPage.value,
pageSize:pageSize.value
},(message)=>{
let a=[]
a=message.rows
console.log(a)
for(let i=0;i<a.length;i++){
if(a[i].isupload==='已上传'){
a[i].summarytime=moment(a[i].summarytime).format('YYYY-MM-DD hh:mm:ss')
}else if(a[i].isupload==='待审核'){a[i].summarytime=moment(a[i].summarytime).format('YYYY-MM-DD hh:mm:ss')
}else {a[i].summarytime=''
}
}
datas.value=a
total.value=message.totalCount
},(message)=>{
ElMessage.warning(message)
})
}

const onError=()=>{
                importDataText.value = '上传述职报告';
                this.importDisabled.value = false;
                this.$message.success("上传失败！");
            }

const onSuccess=()=> {
            	// 成功后文本修改为原来的导入数据
                importDataText.value = '上传述职报告';
                // 将上传组件改为允许使用
                importDisabled.value = false;
                // 调用刷新数据的方法
                findAll();
                // message 弹出消息
                ElMessage.success("导入成功！");
            }

const beforeUpload=()=> {
            	// 将文本修改为正在导入
                importDataText1.value = '正在上传';
                // 将其上传组件暂时禁用
                importDisabled.value = true;
            }

            const onError1=()=>{
                importDataText1.value = '上传述职报告';
                this.importDisabled1.value = false;
                this.$message.success("上传失败！");
            }

const onSuccess1=()=> {
            	// 成功后文本修改为原来的导入数据
                importDataText1.value = '上传批量修改中层干部信息表';
                // 将上传组件改为允许使用
                importDisabled1.value = false;
                // 调用刷新数据的方法
                findAll();
                // message 弹出消息
                ElMessage.success("导入成功！");
            }

const beforeUpload1=()=> {
            	// 将文本修改为正在导入
                importDataText1.value = '正在上传';
                // 将其上传组件暂时禁用
                importDisabled.value = true;
            }

const handleSizeChange=(val)=> {
          pageSize.value=val
          findAll()
        console.log(`每页 ${val} 条`);
      }
const handleCurrentChange=(val)=> {
      currentPage.value=val
      findAll()
        console.log(`当前页: ${val}`);
      }

const look=(row)=>{
window.open('http://localhost:8080/user/look?uid='+row.uid)

}


const changeState=(row, state)=> {
if(state=='审核通过...师傅正在赶来的路上'){
post('/user/checksuccess',{
uid:row.uid
},(message)=>{
findAll()
datas.value=[]
ElMessage.success(message)
},(message)=>{
ElMessage.warning(message)
})
}else{
post('/user/checkfailure',{uid:row.uid},(message)=>{
findAll()
datas.value=[]
ElMessage.success(message)
},(message)=>{
ElMessage.warning(message)
})
}
    }

</script>
<style scoped>

</style>